package com.matt.repository;

import com.matt.domain.NoticeMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/3/23
 * *******************************
 */
public interface NoticeMessageRepository extends JpaRepository<NoticeMessage, String> {
    List<NoticeMessage> findByReceiveIdAndDueStatusAndAreaId(String staffId, Integer dueStatus, String areaId);

    NoticeMessage findByReceiveIdAndCategory(String staffId, Integer category);

    NoticeMessage findByReceiveIdAndCategoryAndLinkId(String staffId, Integer category, String linkId);

    NoticeMessage findByReceiveIdAndCategoryAndLinkIdAndCreatedBetween(String staffId, Integer category, String linkId, Date begin, Date end);

    @Modifying
    Long deleteByLinkIdAndCategory(String linkId, Integer category);

    @Modifying
    Long deleteByLinkIdAndCategoryIn(String linkId, List<Integer> categorys);

    @Modifying
    Long deleteByLinkIdInAndCategoryIn(List<String> linkIds, List<Integer> categorys);

    @Modifying
    Long deleteByLinkIdAndCategoryAndDueDate(String linkId, Integer category, String date);

    @Modifying
    Long deleteByLinkIdInAndCategory(List<String> linkIds, Integer category);

    @Modifying
    Long deleteByLinkId(String linkId);

    @Transactional
    @Modifying
    @Query("update NoticeMessage n set n.dueStatus=:status where n.dueDate<:date")
    void updateByDueDate(@Param("date") Date date, @Param("status") Integer status);
}
